﻿using System;
using Assist;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.Revit;

namespace YJKArch.RoomRoofModule
{
	[Regeneration(RegenerationOption.Manual)]
	[Transaction(TransactionMode.Manual)]
	public class CmdUpdataFloorStruElv : YJKCommandAuto
	{
		protected override Result YJKExcute(ExternalCommandData cmdData, ref string message, ElementSet elements)
		{
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(this.m_doc);
			filteredElementCollector.OfClass(typeof(Floor));
			foreach (Element element in filteredElementCollector.ToElements())
			{
				double num = 0.0;
				Floor floor = element as Floor;
				if (floor != null)
				{
					double elevation = floor.GetYJKLevel().Elevation;
					double num2 = floor.get_Parameter(BuiltInParameter.FLOOR_HEIGHTABOVELEVEL_PARAM).AsDouble();
					foreach (CompoundStructureLayer compoundStructureLayer in floor.FloorType.GetCompoundStructure().GetLayers())
					{
						if ((int)compoundStructureLayer.Function == 1)
						{
							break;
						}
						num += compoundStructureLayer.Width;
					}
					double val = elevation + num2 - num;
					string text = "(" + AssistFunc.feetToMM(val).ToString("0") + ")";
					string text2 = " " + AssistFunc.feetToMM(elevation).ToString("0") + " ";
					floor.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).Set(text);
					floor.get_Parameter(BuiltInParameter.DOOR_NUMBER).Set(text2);
				}
			}
			return Autodesk.Revit.UI.Result.Succeeded;
		}
	}
}
